import Myheader from './components/myheader'
import './index.scss'
import axios from 'axios'
import { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
const AllList = () => {
    const params = useParams()
    console.log(params);
    const { keyword } = params;


    const [alllist, setAllist] = useState([])
    useEffect(() => {
        axios.post('/mcp/v1/search/queryPrd', { "searchSortField": 0, "searchSortType": "desc", "searchFlag": 0, "keyword": keyword, "pageSize": 20, "pageNum": 1, "portal": 21, "version": 350, "lang": "zh-CN", "country": "CNQX", "recommendProductReq": { "lang": "zh-CN", "country": "CNQX", "sceneId": "", "tid": "c3d463a1a9068a4709a851ca11cd5abe", "pageNum": 1, "pageSize": 20, "isRecommended": false, "platformType": "3", "pageType": "", "positionType": "" }, "_areacode": "CNQX", "beCode": "CNQX" }).then(res => {
            console.log(res);
            setAllist(res.data.resultList)
        })

    }, [])


    return <div>
        <Myheader keyword={keyword} />
        <div className='productAll'>
            <div className='wrapper'>
                {alllist.map((item, index) => <div className='subItem' key={index}>
                    <div className='image'><img src={item.photoFullPath} alt="" /></div>
                    <div className='subTitle'>{item.name}</div>
                    <div className='submi'>{item.skuName}</div>
                    <div className='product'>￥{item.price}</div>

                </div>
                )}
            </div>

        </div>

    </div>
}
export default AllList
/*
Component {
    constructor() {
        super(); this.state = {
            mylist: [], end: false, text: false,
        }
        this.page = 1;
        this.total = 0

    }


    componentDidMount() {
        axios.get('/getCategoryPrdList?portal=21&version=350&lang=zh-CN&country=CNQX&_areacode=CNQX&beCode=CNQX&cid=98&pageNumber=1&pagesize=20&sortField=default&sortType=desc&cidLevel=1').then(res => {
            console.log(res);
            this.total = res.data.totalPage;
            this.GetDate();
            this.onScrollFn()

        })
    }
    GetDate = () => {

        if (this.total >= this.page) {
            axios.get('/getCategoryPrdList?portal=21&version=350&lang=zh-CN&country=CNQX&_areacode=CNQX&beCode=CNQX&cid=98&pageNumber=1&pagesize=20&sortField=default&sortType=desc&cidLevel=1').then(res => {

                let data = res.data.cidPrdMap[98]
                this.setState({
                    mylist: [...this.state.mylist, ...data]
                })
            })
        }

    }
    onScrollFn = () => {
        window.onscroll = throttle(() => {
            let scrollTop = document.documentElement.scrollTop | document.body.scrollTop;
            let windowHeight = document.documentElement.clientHeight;
            let scrollHeight = document.body.scrollHeight;

            if (scrollHeight - scrollTop <= windowHeight) {
                this.page++;

                this.setState({
                    text: true
                })
                if (this.page == this.total) {
                    console.log('到底了');
                    this.setState({
                        end: true
                    })
                }
                this.GetDate()
            }
        }, 3000)
    }

    render() {
        const { mylist, end, text } = this.state
      
        )
    }
}
*/